package org.wlgzs.shop.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wlgzs.shop.bean.Coupons;
import org.wlgzs.shop.bean.CouponsExample;
import org.wlgzs.shop.dao.CouponsMapper;
import org.wlgzs.shop.service.ICouponsService;

import java.util.List;

/**
 * @Author: Ben
 * @Date: 2019/5/21 20:55
 * @Project org.wlgzs.shop
 */
@Service(value ="CouponsService" )
public class CouponsServiceImpl implements ICouponsService {
    @Autowired
    CouponsMapper couponsMapper;

    /**
     * 增加红包信息
     * @param coupons
     * @return int
     */
    @Override
    public int insertCouponsService(Coupons coupons) {
        return  couponsMapper.insert(coupons);
    }


    /**
     *根据红包id删除红包信息
     * @param couponsId
     * @return int
     */
    @Override
    public int deleteCouponsService(int couponsId) {
        return couponsMapper.deleteByPrimaryKey(couponsId);
    }

    /**
     * 更改红包信息
     * @param coupons
     * @return int
     */
    @Override
    public int updateCouponsService(Coupons coupons) {
        return couponsMapper.updateByPrimaryKeySelective(coupons);
    }

    /**
     * 根据红包id查询红包信息
     * @param couponsId
     * @return List<Coupons>
     */
    @Override
    public List<Coupons> selectCouponsService(int couponsId) {
        CouponsExample couponsExample=new CouponsExample();
        CouponsExample.Criteria criteria=couponsExample.createCriteria();
        criteria.andCouponsIdEqualTo(couponsId);
        List<Coupons> couponsList=couponsMapper.selectByExample(couponsExample);
        return couponsList;
    }
}
